package src;

import javax.swing.*;
import java.awt.*;

public class CustomerMainFrame extends JFrame {
    private String cardNumber;

    public CustomerMainFrame(String cardNumber) {
        this.cardNumber = cardNumber;
        setTitle("客户系统 - 卡号: " + cardNumber);
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 创建主面板
        JPanel mainPanel = new JPanel(new GridLayout(3, 2, 20, 20));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 创建功能按钮
        JButton balanceButton = new JButton("余额查询");
        JButton depositButton = new JButton("存款");
        JButton withdrawButton = new JButton("取款");
        JButton transferButton = new JButton("转账");
        JButton reportLossButton = new JButton("挂失");
        JButton changePasswordButton = new JButton("修改密码");

        // 设置按钮字体
        Font buttonFont = new Font("微软雅黑", Font.PLAIN, 16);
        balanceButton.setFont(buttonFont);
        depositButton.setFont(buttonFont);
        withdrawButton.setFont(buttonFont);
        transferButton.setFont(buttonFont);
        reportLossButton.setFont(buttonFont);
        changePasswordButton.setFont(buttonFont);

        // 添加按钮事件监听器
        balanceButton.addActionListener(e -> new BalanceQueryDialog(this, cardNumber).setVisible(true));
        depositButton.addActionListener(e -> new DepositDialog(this, cardNumber).setVisible(true));
        withdrawButton.addActionListener(e -> new WithdrawDialog(this, cardNumber).setVisible(true));
        transferButton.addActionListener(e -> new TransferDialog(this, cardNumber).setVisible(true));
        reportLossButton.addActionListener(e -> new ReportLossDialog(this, cardNumber).setVisible(true));
        changePasswordButton.addActionListener(e -> new ChangePasswordDialog(this, cardNumber).setVisible(true));

        // 添加按钮到面板
        mainPanel.add(balanceButton);
        mainPanel.add(depositButton);
        mainPanel.add(withdrawButton);
        mainPanel.add(transferButton);
        mainPanel.add(reportLossButton);
        mainPanel.add(changePasswordButton);

        // 添加退出按钮
        JButton logoutButton = new JButton("退出登录");
        logoutButton.addActionListener(e -> {
            new MainFrame().setVisible(true);
            this.dispose();
        });

        JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        bottomPanel.add(logoutButton);

        // 使用BorderLayout布局
        setLayout(new BorderLayout());
        add(mainPanel, BorderLayout.CENTER);
        add(bottomPanel, BorderLayout.SOUTH);
    }
} 